// diagnose_paths_fixed.js - 诊断路径问题（修正版）
const path = require('path');
const fs = require('fs');

console.log("当前工作目录:", process.cwd());
console.log("__dirname:", __dirname);
console.log("process.execPath:", process.execPath);

// 检查向量存储路径（按照vectorStoreService.js中的方式计算）
const vectorStorePath = path.join(__dirname, '../vector_store');
console.log("计算出的向量存储路径:", vectorStorePath);

// 检查路径是否存在
console.log("向量存储路径是否存在:", fs.existsSync(vectorStorePath));

if (fs.existsSync(vectorStorePath)) {
    const files = fs.readdirSync(vectorStorePath);
    console.log("向量存储目录中的文件:", files);
    
    // 检查具体文件
    const indexPath = path.join(vectorStorePath, 'hnswlib.index');
    console.log("hnswlib.index 路径:", indexPath);
    console.log("hnswlib.index 是否存在:", fs.existsSync(indexPath));
    
    if (fs.existsSync(indexPath)) {
        const stats = fs.statSync(indexPath);
        console.log("hnswlib.index 文件大小:", stats.size, "字节");
    }
}

// 同时检查backend/vector_store路径
const backendVectorStorePath = path.join(__dirname, 'vector_store');
console.log("\nBackend向量存储路径:", backendVectorStorePath);
console.log("Backend向量存储路径是否存在:", fs.existsSync(backendVectorStorePath));

if (fs.existsSync(backendVectorStorePath)) {
    const files = fs.readdirSync(backendVectorStorePath);
    console.log("Backend向量存储目录中的文件:", files);
    
    // 检查具体文件
    const indexPath = path.join(backendVectorStorePath, 'hnswlib.index');
    console.log("Backend hnswlib.index 路径:", indexPath);
    console.log("Backend hnswlib.index 是否存在:", fs.existsSync(indexPath));
    
    if (fs.existsSync(indexPath)) {
        const stats = fs.statSync(indexPath);
        console.log("Backend hnswlib.index 文件大小:", stats.size, "字节");
    }
}